import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_magic_planet/common/constant.dart';
import 'package:flutter_magic_planet/component/toast.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebViewPage extends StatefulWidget {
  final String url;

  const WebViewPage({Key? key, required this.url}) : super(key: key);
  @override
  _WebViewPageState createState() => _WebViewPageState();
}

class _WebViewPageState extends State<WebViewPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('隐私协议'),
        centerTitle: true,
        backgroundColor: primaryColor,
        brightness: Brightness.dark,
        elevation: 0,
      ),
      body: WebView(
        initialUrl: widget.url,
        onPageStarted: (s) {
          Toast.loading();
        },
        onPageFinished: (s) {
          Toast.dismiss();
        },
        onProgress: (index) {},
      ),
    );
  }

  @override
  void initState() {
    super.initState();
    // Enable hybrid composition.
    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }
}
